#!/bin/bash

# 应用名称
APP_NAME="jzsxxzx"
# JAR文件名
JAR_NAME="${APP_NAME}-1.0.0.jar"

# 查找进程ID
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`

# 如果进程存在则终止
if [ -n "$pid" ]; then
    echo "Stopping $APP_NAME (pid=$pid)..."
    kill $pid
    
    # 等待进程结束
    sleep 5
    
    # 再次检查进程是否还存在
    pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
    if [ -n "$pid" ]; then
        echo "Force killing $APP_NAME (pid=$pid)..."
        kill -9 $pid
    fi
    
    echo "$APP_NAME stopped successfully"
else
    echo "$APP_NAME is not running"
fi
